package com.yuba.front.controller.comment;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuba.common.core.domain.R;
import com.yuba.common.core.validate.AddGroup;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.mybatis.core.page.TableDataInfo;
import com.yuba.common.satoken.utils.LoginHelper;
import com.yuba.common.web.core.BaseController;
import com.yuba.front.domain.bo.FishSiteCommentsBo;
import com.yuba.front.domain.param.ActionParam;
import com.yuba.front.domain.param.CommentListParam;
import com.yuba.front.domain.param.CommentParam;
import com.yuba.front.domain.vo.CommentVo;
import com.yuba.front.domain.vo.FishSiteCommentsVo;
import com.yuba.front.service.ICommentPostsService;
import com.yuba.front.service.IFishSiteCommentsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 评论api接口
 *
 * @author modakai
 */

@RestController
@RequestMapping("api/comment")
@RequiredArgsConstructor
public class ApiCommentController extends BaseController {

    private final ICommentPostsService commentPostsService;
    private final IFishSiteCommentsService fishSiteCommentsService;

    /**
     * 发布评论
     * @param body 请求参数
     * @return 无
     */
    @PostMapping("posts")
    public R<Void> pushPostsComment(@Validated(AddGroup.class) @RequestBody CommentParam body) {
        commentPostsService.pushPostsComment(body, LoginHelper.getUserId());
        return R.ok();
    }

    /**
     * 进去帖子评论列表
     * @return 列表
     */
    @SaIgnore
    @PostMapping("posts/page/list")
    public R<Page<CommentVo>> pagePostsList(@RequestBody CommentListParam form) {
        return R.ok(commentPostsService.pagePostsList(form));
    }

    /**
     * 置顶评论
     */
    @PostMapping("posts/top")
    public R<Void> topPostsComment(@RequestBody ActionParam actionParam) {
        commentPostsService.postsCommentTop(actionParam, LoginHelper.getUserId());
        return R.ok();
    }

    /**
     * 删除评论
     */
    @PostMapping("posts/delete")
    public R<Void> deletePostsComment(@RequestBody ActionParam actionParam) {
        commentPostsService.postsCommentDelete(actionParam, LoginHelper.getUserId());
        return R.ok();
    }

    /**
     * 查询钓点评论列表
     * @param pageQuery 查询参数
     * @param fishSiteId 钓点id
     * @return 无
     */
    @SaIgnore
    @GetMapping("fishSite/page/list")
    public R<TableDataInfo<FishSiteCommentsVo>> pageFishSiteComment(PageQuery pageQuery, @RequestParam("fishSiteId") Integer fishSiteId) {
        return R.ok(fishSiteCommentsService.queryPageList(pageQuery, fishSiteId));
    }

    /**
     * 评论钓点
     * @param form 评论数据
     * @return 无
     */
    @PostMapping("fishSite")
    public R<Void> pushFishSiteComment(@RequestBody FishSiteCommentsBo form) {
        fishSiteCommentsService.pushFishSiteComment(form, LoginHelper.getUserId());
        return R.ok();
    }
}
